﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDCRNewEdit.Model;
using LDCRNewEdit.Utils;

namespace LDCRNewEdit.UI.地图编辑.场景地图设计
{
    public partial class SceneJumpForm : Form
    {
        private SceneJump sceneJump = null;

        public SceneJumpForm()
        {
            InitializeComponent();
        }


        public SceneJump ShowJumpDialog(SceneJump sj)
        {
            this.sceneJump = sj;

            this.textBoxX.Text = sj.X.ToString();
            this.textBoxY.Text = sj.Y.ToString();
            this.textBoxSceneID.Text = sj.SceneID;
            this.textBoxToX.Text = sj.ToX.ToString();
            this.textBoxToY.Text = sj.ToY.ToString();

            if (this.ShowDialog() == DialogResult.OK)
            {
                this.Close();
                return this.sceneJump;
            }
            else
            {
                this.Close();
                return null;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = Resources.GetPath("SceneMap");
            ofd.Filter = "*.smap|*.smap";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string name = System.IO.Path.GetFileName(ofd.FileName).Replace(".smap", "");
                this.textBoxSceneID.Text = name;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBoxSceneID.Text))
            {
                MessageBox.Show("请选择跳转目标场景!");
            }
            else if (string.IsNullOrEmpty(this.textBoxToX.Text))
            {
                MessageBox.Show("请输入跳转目标场景的X坐标!");
                this.textBoxToX.Focus();
            }
            else if (string.IsNullOrEmpty(this.textBoxToY.Text))
            {
                MessageBox.Show("请输入跳转目标场景的Y坐标!");
                this.textBoxToY.Focus();
            }
            else
            {
                sceneJump.SceneID = this.textBoxSceneID.Text;
                sceneJump.ToX = short.Parse(this.textBoxToX.Text);
                sceneJump.ToY = short.Parse(this.textBoxToY.Text);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
